package cn.swust.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class sendJson {
	public static void send(HttpServletResponse response,Object obj)
	{
		Gson gson = new Gson();
		String json = null;
		if(obj instanceof String)
		{
			json = (String)json;
		}
		else
		json = gson.toJson(obj);
		System.out.println("json:\n"+json);
		PrintWriter out = null;
		try {
			response.setContentType("application/json; charset=utf-8");
			response.setHeader("Cache-Control", "no-cache");
			out = response.getWriter();
			out.print(json);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			out.flush();
			out.close();
		}			
	}
}
